package sun.scheduler.util.graph;


/**
 * Represents a GraphEdge connecting two nodes.
 * @param <N> the generic type of the {@see Node} data.
 * @param <E> the generic type of the {@see Edge} data.
 * @author mfj
 */
public class Edge<N,E>
{
    /**
     * The data content of this edge.
     */
    protected E data;
    /**
     * The start node.
     */
    protected Node<N, E> start;
    /**
     * The end node.
     */
    protected Node<N, E> end;

    /**
     * The graph of which this edge is an element of.
     */
    protected Graph<N, E> graph;

    /**
     * Instantiates a new <code>Edge</code>.
     * @param data the data content of this edge.
     * @param start the start node of this edge
     * @param end the endnode of this edge
     * @param graph the graph to which this edge belongs to.
     */
    public Edge(E data, Node<N, E> start, Node<N, E> end, Graph<N, E> graph)
    {
        this.data = data;
        this.start = start;
        this.end = end;
        this.graph = graph;
    }


    /**
     * Sets the data content of this edge.
     * @param data
     */
    public void setData(E data)
    {
        this.data = data;
    }


    /**
     * Gets the data content of this edge.
     * @return the data content.
     */
    public E getData()
    {
        return data;
    }


    /**
     * Gets the end node of this edge.
     * @return
     */
    public Node<N, E> getEnd()
    {
        return end;
    }


    /**
     * Gets the startnode of this edge.
     * @return
     */
    public Node<N, E> getStart()
    {
        return start;
    }


    /**
     *
     * @return
     */
    @Override
    public String toString()
    {
        return "(" + start.id + "->" + end.id + ", data=" + data + ")";
    }


    /**
     *
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj)
    {
        return this ==  obj;
    }


    /**
     *
     * @return
     */
    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += start.id;
        hash += end.id << (graph.getNumOfNodes() % 16);
        return hash;
    }
}